package CustSys;

public class CustomerView {
    private CustomerList customerList = new CustomerList(10);
    private CustomerView(){
        Customer customer = new Customer("张三", '男', 30, "010-56253825",
                "abc@email.com");
        customerList.addCustomer(customer);
    }

    public void enterMainMenu(){
        boolean flag = true;
        do{
            System.out
                    .println("\n-----------------客户信息管理软件-----------------\n");
            System.out.println("                   1 添 加 客 户");
            System.out.println("                   2 修 改 客 户");
            System.out.println("                   3 删 除 客 户");
            System.out.println("                   4 客 户 列 表");
            System.out.println("                   5 退       出\n");
            System.out.print("                   请选择(1-5)：");

            char c = CMUtility.readMenuSelection();
            switch (c){
                    case '1':
                        addNewCustomer();
                        break;
                    case '2':
                        modifyCustomer();
                        break;
                    case '3':
                        deleteCustomer();
                        break;
                    case '4':
                        listAllCustomers();
                        break;
                    case '5':
                        char c1 = CMUtility.readConfirmSelection();
                        if(c1 == 'y'){
                            flag = false;
                            break;
                        }
            }
        }while (flag);
    }

    private void modifyCustomer() {
        int index = 0;
        Customer cust = null;
        for(;;){
            System.out.println("请输入要修改的编号");
            index = CMUtility.readInt();
            if(index == -1){
                break;
            }
            cust = customerList.getCustomer(index - 1);
            if(cust == null){

            }

        }
    }

    public void addNewCustomer(){
        System.out.println("---------------------添加客户---------------------");
        System.out.print("姓名：");
        String name = CMUtility.readString(4);
        System.out.print("性别：");
        char gender = CMUtility.readChar();
        System.out.print("年龄：");
        int age = CMUtility.readInt();
        System.out.print("电话：");
        String phone = CMUtility.readString(15);
        System.out.print("邮箱：");
        String email = CMUtility.readString(15);

        Customer customer = new Customer(name, gender, age, phone, email);
        boolean b = customerList.addCustomer(customer);
        if(b){

        }else{

        }
    }
}
